#include "commands.h"

Cdcommands* Cdcommands::Instance ()
{
	static Cdcommands t;
	return &t;
}

Cdcommands::Cdcommands() : BeCommandSystem()
{
}

// Executing commands
void Cdcommands::execCmd(const string& name)
{
	if 	( cmdlist[name]->commandtype == T_CUSTOM0 )
		( scene->*static_cast<cmd2*>( cmdlist[name] )->customMember )();
	else
		generalExecCmd(name);
}

void Cdcommands::execCmd(const string& name, const string& str)
{
	if 	( cmdlist[name]->commandtype == T_CUSTOM0 )
		( scene->*static_cast<cmd2*>( cmdlist[name] )->customMember_string )(str);
	else
		generalExecCmd(name, str);
}

void Cdcommands::execCmd(const string& name, int ui)
{
	if 	( cmdlist[name]->commandtype == T_CUSTOM0 )
		( scene->*static_cast<cmd2*>( cmdlist[name] )->customMember_int )(ui);
	else
		generalExecCmd(name, ui);
}

void Cdcommands::execCmd(const string& name, float floatingpoint)
{
	if 	( cmdlist[name]->commandtype == T_CUSTOM0 )
		( scene->*static_cast<cmd2*>( cmdlist[name] )->customMember_float )(floatingpoint);
	else
		generalExecCmd(name, floatingpoint);
}

// Registering commands
void Cdcommands::registerCmd(string name, void (Scene::*pt2Func)())
{
	cmd2* c = new cmd2();
	c->commandtype		= T_CUSTOM0;
	c->argtype		= A_NOARG;
	c->customMember		= pt2Func;
	cmdlist[name]		= c;
}

void Cdcommands::registerCmd(string name, void (Scene::*pt2Func)(int))
{
	cmd2* c = new cmd2();
	c->commandtype		= T_CUSTOM0;
	c->argtype		= A_INT;
	c->customMember_int	= pt2Func;
	cmdlist[name]		= c;
}

void Cdcommands::registerCmd(string name, void (Scene::*pt2Func)(float))
{
	cmd2* c = new cmd2();
	c->commandtype		= T_CUSTOM0;
	c->argtype		= A_FLOAT;
	c->customMember_float	= pt2Func;
	cmdlist[name]		= c;
}

void Cdcommands::registerCmd(string name, void (Scene::*pt2Func)(const string&))
{
	cmd2* c = new cmd2();
	c->commandtype		= T_CUSTOM0;
	c->argtype		= A_STRING;
	c->customMember_string	= pt2Func;
	cmdlist[name]		= c;
}

Cdcommands::~Cdcommands()
{
}


